package com.appspot.modutajataja;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import com.facebook.model.GraphUser;

public class MainActivity extends Activity {

	String[] nameList = { "Yoon Ah", "Seo Hyeon", "Tae Yeon", "Soo Young",
			"Jessica", "Yoo Ri", "Tiffany", "Hyo Yeon", "Sunny" };
	String[] recordList = { "00 : 33 : 33", "00 : 34 : 44", "00 : 35 : 45",
			"00 : 42 : 98", "00 : 45 : 12", "00 : 50 : 01", "00 : 58 : 46",
			"01 : 01 : 12", "01 : 45 : 78" };

	MyAdapter adapter;
	ListView listView;
	Button button_game;
	Button button_event;
	Button button_option;
	
	Intent intent;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		TextView textView = (TextView) findViewById(R.id.text_ad);
		Animation ani = new AlphaAnimation(0.2f, 2f);
		ani.setRepeatMode(Animation.REVERSE);
		ani.setRepeatCount(Animation.INFINITE);
		ani.setDuration(1000);
		textView.startAnimation(ani);
			
//			String name = getIntent().getStringExtra("name");
//			String id = getIntent().getStringExtra("id");
//			textView.setText(name + "님("+id+") 환영합니다!");


		



		WebView webView = (WebView)findViewById(R.id.main_WebView);
		WebSettings sets = webView.getSettings();
		sets.setJavaScriptEnabled(true);
		webView.loadUrl("file:///android_asset/newsticker/newsticker.html");

		button_game = (Button) findViewById(R.id.button_game);
		button_game.setOnClickListener(new MyHandler());

		button_event = (Button) findViewById(R.id.button_event);
		button_event.setOnClickListener(new MyHandler());

		button_option = (Button) findViewById(R.id.button_option);
		button_option.setOnClickListener(new MyHandler());

		adapter = new MyAdapter(this);
		listView = (ListView) findViewById(R.id.main_ListView);
		listView.setDivider(null);
		listView.setAdapter(adapter);

	} // end of onCreate method

	class MyHandler implements OnClickListener {

		@Override
		public void onClick(View v) {

			if (v.getId() == R.id.button_game) {
				Intent intent = new Intent(MainActivity.this, GameActivity.class);
				startActivity(intent);
			} else if (v.getId() == R.id.button_event) {
				Intent intent = new Intent(MainActivity.this, EventActivity.class);
				startActivity(intent);
			} else if (v.getId() == R.id.button_option) {
				Intent intent = new Intent(MainActivity.this, OptionActivity.class);
				startActivity(intent);
			}
		}
	} // end of MyHandler Class

	// adapter Class
	class MyAdapter extends ArrayAdapter {
		Context mc;

		public MyAdapter(Context context) {
			super(context, R.layout.list_item, nameList);
			mc = context;
		}

		@Override
		public int getCount() {
			return nameList.length;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {

			LayoutInflater inflater = (LayoutInflater) mc.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			View root = inflater.inflate(R.layout.list_item, null);

			TextView rank = (TextView) root.findViewById(R.id.list_no);
			TextView user_name = (TextView) root.findViewById(R.id.list_username);
			TextView user_record = (TextView) root.findViewById(R.id.list_timerecord);

			rank.setText("" + (position + 1));
			user_name.setText(nameList[position]);
			user_record.setText(recordList[position]);

			return root;

		} // end of getView method
	} // end of MyAdapter class
}; // end of MainActivity class